clear
do "...\First.do"


clear 
use "$work\patient_gp_year.dta"

keep pnr ydernr year

merge 1:1 pnr year using "$work\full_sample.dta", keepus(low_ses)
keep if _merge==3
drop _merge

bys ydernr year: egen mean_low_ses_ydernr=mean(low_ses)
keep ydernr year mean_low_ses_ydernr
duplicates drop

save "$work\mean_ses_yder.dta", replace
